﻿(function ($) {
    $.fn.regexMask = function (mask) {
        if (!mask) {
            throw 'mandatory mask argument missing';
        }
            /*else if (mask == 'float-ptbr') {
                mask = /^((\d{1,3}(\.\d{3})*(((\.\d{0,2}))|((\,\d*)?)))|(\d+(\,\d*)?))$/;
            } else if (mask == 'float-enus') {
                mask = /^((\d{1,3}(\,\d{3})*(((\,\d{0,2}))|((\.\d*)?)))|(\d+(\.\d*)?))$/;
            }*/
        else if (mask == 'integer') {
            mask = /^\d+$/;
        } else if (mask == 'time') {
            mask = /^(([0-1][0-9]|2[0-3]|[0-9])|([0-1][0-9]|2[0-3]|[0-9])(:|h)[0-5]?[0-9]?)$/;
        }
        else {
            try {
                mask.test("");
            } catch (e) {
                throw 'mask regex need to support test method';
            }
        }
        $(this).focusout(function () {
            var val = $(this).val();
            if (val == null || val == "") {
                return true;
            }
            else if (!mask.test(val)) {
                $(this).css("border-color", "red");
                $(this).attr("placeholder", "hh:mm");
                $(this).focus();
            }
            return true;
        });
    };
})(jQuery);